package langnstats.project.lib.clustering;

import java.util.HashMap;
import java.util.Map;

import langnstats.project.lib.WordType;
import langnstats.project.tools.CountMap;

public abstract class AbstractClusterer implements Clusterer {
	private CountMap<Integer> clusterCount = null;
	
	public boolean areInSameCluster(WordType wt1, WordType wt2){
		return this.getClusterID(wt1)== this.getClusterID(wt2);
	}
	
	public int countWordTypeInSameCluster(WordType wt){
		if(clusterCount==null){
			clusterCount = new CountMap<Integer>();
			for(WordType wordType : WordType.values()){
				clusterCount.increCount(this.getClusterID(wordType));
			}
		}
		return clusterCount.getCount(this.getClusterID(wt));
	}
	
	public Map<WordType,Double> getClusteredProbMap(CountMap<WordType> map){
		CountMap<Integer> tmpMap = new CountMap<Integer>();
		for(Map.Entry<WordType,Integer> entry : map.entrySet()){
			tmpMap.addCount(this.getClusterID(entry.getKey()), entry.getValue());
		}
		
		Map<Integer,Double> predictionMap = tmpMap.getProportionMap();
		
		Map<WordType,Double> returnMap = new HashMap<WordType,Double>();
		for(WordType wordType : WordType.values()){
			int id = this.getClusterID(wordType);
			double prob = this.getProbability(wordType, predictionMap.get(id));
			returnMap.put(wordType, prob);
		}
		
		return returnMap;
	}
}
